import os
from typing import Optional

class Settings:
    """应用程序配置设置"""
    
    # 数据库配置
    DB_HOST: str = os.environ.get('DB_HOST', 'localhost')
    DB_USER: str = os.environ.get('DB_USER', 'root')
    DB_PASSWORD: str = os.environ.get('DB_PASSWORD', 'abc123')
    DB_NAME: str = os.environ.get('DB_NAME', 'course_evaluation_system')
    
    # JWT配置
    SECRET_KEY: str = os.environ.get('SECRET_KEY', 'your-default-secret-key-change-in-production')
    JWT_ALGORITHM: str = os.environ.get('JWT_ALGORITHM', 'HS256')
    ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.environ.get('ACCESS_TOKEN_EXPIRE_MINUTES', '120'))
    
    # 服务器配置
    HOST: str = os.environ.get('HOST', '0.0.0.0')
    PORT: int = int(os.environ.get('PORT', '8000'))
    DEBUG: bool = os.environ.get('DEBUG', 'True').lower() == 'true'
    
    # CORS配置 - 允许常用的开发端口
    CORS_ORIGINS: list = [
        "http://localhost:3000",
        "http://localhost:5500",
        "http://localhost:5501",
        "http://localhost:8080",
        "http://127.0.0.1:3000",
        "http://127.0.0.1:5500",
        "http://127.0.0.1:5501",
        "http://127.0.0.1:8080"
    ]
    
    @property
    def db_config(self) -> dict:
        """返回数据库配置字典"""
        return {
            'host': self.DB_HOST,
            'user': self.DB_USER,
            'password': self.DB_PASSWORD,
            'database': self.DB_NAME
        }

# 创建设置实例
settings = Settings() 